package com.fzj.example.jdk18;

import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map;
import java.util.function.*;

/**
 * ClassName: MethodReference
 * date: 2019/11/13 9:40
 * Description: TODO
 *
 * @author fanzj@bonree.com
 * @since JDK 1.8
 */
public class MethodReferenceDemo {

    public static void main(String[] args) {
        //传统形式(m)->System.out.println(m)
        //对象的引用 :: 实例方法名,实例化对象，左侧是抽象方法的具体实现
        PrintStream printStream=System.out;
        Consumer<String> consumer=printStream::println;
        consumer.accept("对象的引用::实例方法名,实例化对象，左侧是抽象方法的具体实现");
        //类名 :: 静态方法名
        BiFunction<Integer,Integer,Integer> biFunction=Math::min;
        Consumer<String> result=printStream::println;
        result.accept("类名::静态方法名,函数式求最小值:"+biFunction.apply(130,230));
        //类名 :: 实例方法名
        BiPredicate<String,String> biPredicate=String::equals;
        if(biPredicate.test("fdaf","fdaf")){
            printStream.println("字符串相等");
        }
        //构造器引用，不能为Object::new,new 谁分析：都是接口，假如实现，那就出参肯定要声明或者具体化
        Supplier<FlyDemo> supplier=FlyDemo::new;
        System.out.println(supplier.get().getX());
        System.out.println(supplier.get().getY());
        Function<String,Object> function=String::new;
        //对应也是输出dfafad
        System.out.println(function.apply("dfafad"));
        //给对象赋值
        BiFunction<String, String, FlyDemo > function23 = FlyDemo::new;
        System.out.println(function23.apply("fzj","29").getX());
        System.out.println(function23.apply("fzj","29").getY());
        //数组引用,前者代表长度
        Function<Integer,FlyDemo[]> function1=FlyDemo[]::new;
        FlyDemo[] arr=function1.apply(20);
        System.out.println("数组长度:"+arr.length);
    }
}
